home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2686 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: news.mindlink.net!news
  2. From: brent_bysouth@mindlink.bc.ca (Brent Bysouth)
  3. Newsgroups: comp.lang.c++,comp.lang.pascal.delphi.misc
  4. Subject: Re: C++ with Zapp vs. Delphi
  5. Date: Fri, 19 Jan 1996 03:14:12 GMT
  6. Organization: MIND LINK! - British Columbia, Canada
  7. Message-ID: <4dn30q$o7s@fountain.mindlink.net>
  8. References: <4coar6$d4n@sun4.bham.ac.uk> <4coip7$69s@news1.usa.pipeline.com> <DBk8wg2yqjbB083yn@iaccess.za> <4d7pmb$48c8@tigger.cc.uic.edu> <4dk38h$gdr@merlin.delphi.com> <4dksp1$3d6c@tigger.cc.uic.edu>
  9. NNTP-Posting-Host: line085.nwm.mindlink.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. olczyk@sunphy1 (Jung Oh) wrote:
  13.  
  14.  
  15. >How do you write a class SortedList which maintains a list of objects which 
  16. >have a method CompareTo. This lists keeps the objects in sorted order based
  17. >on CompareTo. You also know that 
  18.  
  19. You can do this in Delphi using 
  20.  
  21. a) messaging:
  22.  
  23. retcode := object.Dispatch(msgCompareTo);
  24.  
  25. - where msgCompareTo is a message type that you defined, and the
  26. CompareTo method is declared as message method in the contained
  27. classes.  Note that this is how control components in Delphi handle
  28. messages from Windows.
  29.  
  30. b) MethodAddress:
  31.  
  32. var
  33.   compareTo: TMethod;
  34. begin
  35.  
  36.     compareTo.Data := object;
  37.     compareTo.Code := object.MethodAddress('CompareTo');
  38.     if compareTo.Code <> nil then
  39.         retcode := TCompareTo(compareTo) ( {params} );
  40.  
  41. end;
  42.  
  43. - where TCompareTo is a method type that you define for the CompareTo
  44. signature.  One caveat using this approach:  CompareTo must be
  45. published in the contained classes.
  46.  
  47.  
  48. -----------
  49.  
  50. It's not as elegant as other languages (Smalltalk comes to mind), but
  51. it works.  At some time I may be completing a package that makes all
  52. of this more transparent, but there probably won't be a need as Delphi
  53. 2.0 apparently supports dynamically typed types...
  54.  
  55.  
  56. --------------------------------------------------
  57. brent_bysouth@mindlink.bc.ca
  58. VB, Delphi & SQL Development
  59. Vancouver, BC.
  60. (604) 689-2616
  61. -------------------------------------------------
  62.  
  63.